package com.example.user.myhjjf_app.view;

import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;

import com.alibaba.fastjson.JSON;
import com.baidu.mapapi.map.BaiduMap;
import com.baidu.mapapi.map.MapPoi;
import com.baidu.mapapi.map.MapView;
import com.baidu.mapapi.model.LatLng;
import com.baidu.mapapi.search.district.DistrictResult;
import com.baidu.mapapi.utils.SpatialRelationUtil;
import com.example.user.myhjjf_app.R;
import com.example.user.myhjjf_app.model.Model_Area;
import com.example.user.myhjjf_app.presenter.ListDistrictResult;
import com.example.user.myhjjf_app.presenter.MvpPainting;
import com.example.user.myhjjf_app.presenter.Presenter_Painting;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class Activity_Login extends AppCompatActivity{
    @BindView(R.id.bmapView)
    MapView bmapView;
    public static BaiduMap baiduMap;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity__login);
        ButterKnife.bind(this);
        String[] keyArray = {"兴义市", "兴仁县", "安龙县", "贞丰县", "晴隆县", "普安县", "册亨县", "望谟县"};
        int[] colorArray = {0x40ff0000,0x40000000, 0x400000ff, 0x4000ffff,0x40444444, 0x4000ff00, 0x40CFCFCF, 0x40EE00EE};
        baiduMap = bmapView.getMap();
        baiduMap.setOnMapClickListener(new BaiduMap.OnMapClickListener() {
            @Override
            public void onMapClick(LatLng latLng) {
                for (DistrictResult districtResult : ListDistrictResult.getListDistrictResult().getList()){
                for (List<LatLng> latLngs : districtResult.getPolylines()){
                if (SpatialRelationUtil.isPolygonContainsPoint(latLngs, latLng)) {
                    Intent intent = new Intent(Activity_Login.this,Activity_District.class);
                    intent.putExtra("districtResult",districtResult);
                    startActivity(intent);
                    return;
                }
            }
        }
     }

            @Override
            public boolean onMapPoiClick(MapPoi mapPoi) {
                return false;
            }
        });
        baiduMap.setMapType(BaiduMap.MAP_TYPE_SATELLITE);
        for (int i = 0; i < keyArray.length; i++) {
            MvpPainting painting = new Presenter_Painting();
            painting.getPainting(keyArray[i],colorArray[i]);
        }

    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        bmapView.onDestroy();
    }

    @Override
    protected void onResume() {
        super.onResume();
        bmapView.onResume();
    }

    @Override
    protected void onPause() {
        super.onPause();
        bmapView.onPause();
    }
}
